package everyday;

public class T1027 {
    public int longestArithSeqLength(int[] nums) {
        int len = nums.length;
        int[][] dp = new int[len][1001];
        int res = 0;
        for (int i = 1; i < len; i++) {
            for (int j = 0; j < i; j++) {
                int diff = nums[i] - nums[j] + 500;
                dp[i][diff] = Math.max(2, dp[j][diff] + 1);
                res = Math.max(res, dp[i][diff]);
            }
        }
        return res;
    }
}
